const path = require('path');
const _ =  require('lodash');
const chalk = require('chalk');
const config = require('./config');
const fs = require('fs');


module.exports = {
    calcPath: function(moduleName = _.noop) {
        // 目录换算
        const basePath = path.resolve(__dirname, '../');
        const srcPath = path.resolve(basePath, 'src');

        if( process.argv.length < 3 ) {
            console.info(chalk.red('缺失参数: 模块名称...'));
            return false;
        }

        if( moduleName === _.noop ) moduleName = process.argv[ process.argv.length - 1 ];
        const modulePath = path.resolve(srcPath, config.prefix.project, moduleName);
        
        try {
            fs.statSync(modulePath);
            return { basePath, srcPath, moduleName, modulePath };
        } catch(exception) {
            console.info(chalk.red(exception));
            return false;
        }
    }
}